package com.fancy.learncenter.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.adapter.TopNewsAdapter;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.TopNewsDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

public class TopNewsActivity extends BaseActivity {

    ArrayList<String> itemDatas = new ArrayList<>();

    @Bind(R.id.recycleView)
    RecyclerView recycleView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_top_news, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);
        initToolbar("头条列表");


        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(linearLayoutManager);

        newsAdapter = new TopNewsAdapter(this, new ArrayList<TopNewsDataBean>());
        recycleView.setAdapter(newsAdapter);

        getAccount();
    }

    TopNewsAdapter newsAdapter;

    private void getAccount() {
        Map maps = new HashMap();
        HttpMehtod.getInstance().topListNews(maps, new IdeaObserver<BaseDataBean<List<TopNewsDataBean>>>(this, true) {

            @Override
            public void onSuccess(BaseDataBean<List<TopNewsDataBean>> listBaseDataBean) {

                if (listBaseDataBean.getData() != null) {
                    newsAdapter.notifyDataSetChanged((ArrayList<TopNewsDataBean>) listBaseDataBean.getData());
                }
            }

            @Override
            public void onFail(int errorCode) {

            }

        });
    }
}
